<?php
namespace App\Modules\Goods;

use App\Modules\AdapterApi;
use App\Services\Goods\GoodsIndex;


/**
 * Class Goods 商品 应用层
 * @package App\Modules\Goods
 */
class Goods extends AdapterApi{

    /*----------------------------------------前台接口----------------------------------------------*/
    /*全部商品列表*/
    public function goodsList(): array
    {
        $data = pick_array($this->postData, ['keywords']);
        return GoodsIndex::Goods()->goodsList($data);
    }

    /*商品详情*/
    public function goodsInfo(): array
    {
        $data = pick_array($this->postData, ['id']);
        return GoodsIndex::Goods()->goodsInfo($data);
    }

    /*传商品id和数量返回多少价格*/
    public function goodsPrice(): array
    {
        $data = pick_array($this->postData, ['id','number']);
        return GoodsIndex::Goods()->goodsPrice($data);
    }

    /*最新商品列表（4个）*/
    public function newGoodsList(): array
    {
        return GoodsIndex::Goods()->newGoodsList();
    }
    /*----------------------------------------后台接口----------------------------------------------*/
    /*增*/
    public function addGoods(): array
    {
        $data = pick_array($this->postData, ['title', 'desc', 'price', 'remain', 'img_url']);
        return GoodsIndex::Goods()->addGoods($data);
}

    /*删*/
    public function delGoods(): array
    {
        $data = pick_array($this->postData, ['id']);
        return GoodsIndex::Goods()->delGoods($data);
    }

    /*改*/
    public function altGoods(): array
    {
        $data = pick_array($this->postData, ['id','title', 'desc', 'price', 'remain', 'img_url']);
        return GoodsIndex::Goods()->altGoods($data);
    }

}
